<?php
namespace app\index\model;

use app\common\model\Common;
use think\facade\Db;

class UserLog extends Common
{

    const USER_LOGIN    = 'user login';     //登录
    const USER_LOGOUT   = 'user logout';    //退出
    const USER_REG      = 'user reg';    //注册
    const USER_EDIT     = 'user edit';    //用户编辑信息

    /**
     * 添加日志
     * @param $user_id
     * @param $state
     * @param array $data
     */
    public static function setLog( $user_id,$state,$data = [] )
    {
        $data = [
            'user_id'   => $user_id,
            'state'     => $state,
            'ctime'     => getUtcTime(),
            'params'    => json_encode($data),
            'broswer'   => $_SERVER['HTTP_USER_AGENT'] ?? '',
            'ip'        => get_client_ip(0,true)
        ];
        Db::name('user_log')->save($data);
    }

}